package com.question.mapper;

import com.question.annotation.AutoFill;
import com.question.enumeration.OperationType;
import com.question.pojo.dto.UserFavoriteQuestionDTO;
import com.question.pojo.entity.UserFavorites;
import com.question.pojo.vo.UserFavoriteQuestionVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface FavoriteMapper {

    /**
     * 根据用户ID和题目ID查询收藏状态
     * @param userFavorites
     * @return
     */
    @Select("SELECT * FROM user_favorites WHERE user_id = #{userId} AND question_id = #{questionId}")
    Boolean findByUserIdAndQuestionId(UserFavorites userFavorites);

    /**
     * 根据用户id和题目id删除收藏记录
     * @param userFavorites
     */
    @Delete("DELETE FROM user_favorites WHERE user_id = #{userId} AND question_id = #{questionId}")
    void deleteByUserIdAndQuestionId(UserFavorites userFavorites);

    /**
     * 添加收藏记录
     * @param userFavorites
     */
    @AutoFill(OperationType.CREATED_AT)
    @Select("INSERT INTO user_favorites (user_id, question_id) VALUES (#{userId}, #{questionId})")
    void insert(UserFavorites userFavorites);

    /**
     * 查询用户收藏的题目
     * @param userId
     * @param favoriteQuestionDTO
     * @return
     */
    List<UserFavoriteQuestionVO> listAllQuestions(Long userId, UserFavoriteQuestionDTO favoriteQuestionDTO);
}
